import { ElButton, ElSpace } from 'element-plus'
import { defineComponent } from 'vue'
import { VxeGrid } from 'vxe-table'

import type { IOnlinePageItem } from '@/apis'
import { usePageHeight } from '@/hooks'

import { useGrid } from './hooks'

export default defineComponent({
  setup() {
    const gridHook = useGrid()
    const { pageHeightPx } = usePageHeight()

    return {
      ...gridHook,
      pageHeightPx
    }
  },
  render() {
    return (
      <div
        style={{
          height: this.pageHeightPx
        }}
      >
        <VxeGrid ref={(e: any) => (this.gridRef = e)} {...this.gridConfig}>
          {{
            columns_operation: ({ row }: { row: IOnlinePageItem }) => (
              <ElSpace>
                <ElButton
                  type="primary"
                  size="small"
                  link
                  onClick={() => this.handleOffline(row.tokenId)}
                >
                  下线
                </ElButton>
              </ElSpace>
            )
          }}
        </VxeGrid>
      </div>
    )
  }
})
